package cn.edu.zafu.bigdata.Wym;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Wym_findMax {

    public static <T extends Comparable<T>> T findMax(List<T> list){
        if(list == null || list.isEmpty()){
            return null;
        }
        T max =list.get(0);
        for (int i=1;i<list.size();i++){
            T max1=list.get(i);
            if(max1.compareTo(max)>0){
                max=max1;
            }
        }
        return max;
    }

    public static void main(String[] args){
        List<Integer> intlist=new ArrayList<>(Arrays.asList(1,3,9,2,8,5));//创建整数型列表
        Integer maxint = findMax(intlist);
        System.out.println("Max Integer；"+maxint);

        List<String> stringList=new ArrayList<>(Arrays.asList("absc","sggavx","tweugdhdg","shxvnbz"));//创建字符串型列表
        String maxString = findMax(stringList);
        System.out.println("Max String:"+maxString);
    }

}
